<template>
	<view class="agent-page">
		<view class="page-list">
			<view class="page-item" @click="navigatorPage('/pages/agent/income')">
				<image src="../../static/images/agent/money.png" class="image"></image>
				<view class="title">总收入</view>
			</view>
			<view class="page-item" @click="navigatorPage('/pages/agent/usageRecord')">
				<image src="../../static/images/agent/use.png" class="image"></image>
				<view class="title">使用记录</view>
			</view>
			<view class="page-item" @click="navigatorPage('/pages/agent/dayRecord')">
				<image src="../../static/images/agent/day.png" class="image"></image>
				<view class="title">日报表</view>
			</view>
			<view class="page-item" @click="navigatorPage('/pages/agent/monthRecord')">
				<image src="../../static/images/agent/month.png" class="image"></image>
				<view class="title">月报表</view>
			</view>
		</view>
		<view class="income-box">
			<view class="title-box">
				<image src="../../static/images/agent/zonglan.png" class="image"></image>
				<view class="title">收入概览</view>
			</view>
			<view class="income-list">
				<view class="income-item">
					<view class="title">当天收入(元)</view>
					<view class="money day">+{{dataFrom.today_income}}</view>
					<view class="order">{{dataFrom.today_order}}单</view>
				</view>
				<view class="income-item"></view>
				<view class="income-item">
					<view class="title">当月收入(元)</view>
					<view class="money">+{{dataFrom.month_income}}</view>
					<view class="order">{{dataFrom.month_order}}单</view>
				</view>
				<view class="income-item">
					<view class="title">当年收入(元)</view>
					<view class="money">+{{dataFrom.year_income}}</view>
					<view class="order">{{dataFrom.year_order}}单</view>
				</view>
			</view>
		</view>
		<view class="income-box">
			<view class="title-box">
				<image src="../../static/images/agent/baobiao.png" class="image"></image>
				<view class="title">月收入增长曲线</view>
			</view>
			<view class="income-cart">
				<qiun-data-charts type="column" :chartData="chartsDataColumn"
					:directory="environment=='development'?'/dailitest/':'/daili/'" :canvas2d="true"
					:echartsH5="true" />
			</view>
		</view>
	</view>
</template>

<script>
	import api from '@/api/index.js';
	import systemConfig from "@/api/request.js"
	export default {
		data() {
			return {
				environment: systemConfig.environment,
				dataFrom: [],
				chartsDataColumn: {
					"categories": [],
					"series": [{
						"name": "月收入(元)",
						"data": []
					}]
				}
			}
		},
		onLoad() {
			this.getinitData()
			this.getCurrentIncome()
		},
		methods: {
			navigatorPage(page) {
				uni.navigateTo({
					url: page
				})
			},
			getCurrentIncome() {
				api.getCurrentIncome().then(res => {
					if (res.code == 1) {
						this.dataFrom = res.data
					}
				})
			},
			getinitData() {
				api.getLastMonthsIncome().then(res => {
					if (res.code == 1) {
						this.chartsDataColumn.categories = Object.keys(res.data);
						this.chartsDataColumn.series[0].data = Object.values(res.data);
						this.chartsDataColumn.series[0].linearGradient = [0, 0, 0, 1, [{
							offset: 0,
							color: '#0EE2F8'
						}, {
							offset: 1,
							color: '#1890FF'
						}]];
					}
				})
			},
		}
	}
</script>

<style lang="scss" scoped>
	.agent-page {
		min-height: 100vh;
		background-color: #ededed;

		.page-list {
			display: flex;
			align-items: center;
			justify-content: space-between;
			padding: 20rpx;
			background-color: #ffffff;

			.page-item {
				text-align: center;

				.image {
					width: 120rpx;
					height: 120rpx;
				}

				.label {
					margin-top: 20rpx;
				}
			}
		}

		.income-cart {
			margin: 20rpx;
			padding: 20rpx;
			background-color: #ffffff;
			border-radius: 20rpx;
			height: 400rpx;
		}

		.income-box {
			margin: 20rpx;
			padding: 20rpx;
			background-color: #ffffff;
			border-radius: 20rpx;

			.title-box {
				display: flex;
				align-items: center;

				.image {
					width: 40rpx;
					height: 40rpx;
					margin-right: 20rpx;
				}

				.title {
					font-size: 32rpx;
					font-weight: bold;
				}
			}

			.income-list {
				display: flex;
				flex-wrap: wrap;
				justify-content: space-between;

				.income-item {
					width: 50%;
					margin-top: 20rpx;

					.title {
						color: #696969;
					}

					.money {
						margin: 10rpx 0;
						font-size: 36rpx;
						font-weight: bold;
					}

					.day {
						color: #de6c7d;
					}

					.order {
						background-color: #5897ff;
						color: #ffffff;
						padding: 4rpx 20rpx;
						width: fit-content;
						border-radius: 20rpx;
					}
				}
			}
		}
	}
</style>